<template>
  <el-card v-if="isVirtualTrading && virtualTradingResults.trades.length > 0" shadow="hover" style="margin-top: 20px; background: #f8fafc; border: 1px solid #e2e8f0;">
    <template #header>
      <div style="display: flex; align-items: center; gap: 8px;">
        <el-icon color="#3b82f6"><DataAnalysis /></el-icon>
        <span style="color: #3b82f6; font-weight: bold;">交易统计分析</span>
      </div>
    </template>
    
    <el-row :gutter="15">
      <!-- 基本统计 -->
      <el-col :span="6">
        <div class="stat-card">
          <div class="stat-title">交易次数</div>
          <div class="stat-number">{{ virtualTradingStatistics.totalTrades }}</div>
          <div class="stat-detail">
            盈利: {{ virtualTradingStatistics.winningTrades }} | 亏损: {{ virtualTradingStatistics.losingTrades }}
          </div>
        </div>
      </el-col>
      
      <el-col :span="6">
        <div class="stat-card">
          <div class="stat-title">胜率</div>
          <div class="stat-number" :class="virtualTradingStatistics.winRate >= 50 ? 'profit' : 'loss'">
            {{ virtualTradingStatistics.winRate }}%
          </div>
          <div class="stat-detail">
            盈亏比: {{ virtualTradingStatistics.profitFactor || 'N/A' }}
          </div>
        </div>
      </el-col>
      
      <el-col :span="6">
        <div class="stat-card">
          <div class="stat-title">平均盈亏</div>
          <div class="stat-number">
            <span class="profit">+${{ virtualTradingStatistics.averageWin }}</span> / 
            <span class="loss">-${{ virtualTradingStatistics.averageLoss }}</span>
          </div>
          <div class="stat-detail">
            最大: <span class="profit">+${{ virtualTradingStatistics.maxWin }}</span> / 
            <span class="loss">${{ virtualTradingStatistics.maxLoss }}</span>
          </div>
        </div>
      </el-col>
      
      <el-col :span="6">
        <div class="stat-card">
          <div class="stat-title">最大回撤</div>
          <div class="stat-number loss">
            ${{ virtualTradingStatistics.maxDrawdown }}
          </div>
          <div class="stat-detail">
            {{ virtualTradingStatistics.maxDrawdownPercent }}%
          </div>
        </div>
      </el-col>
    </el-row>
    
    <el-row :gutter="15" style="margin-top: 15px;">
      <el-col :span="8">
        <div class="stat-card">
          <div class="stat-title">总收益率</div>
          <div class="stat-number" :class="virtualTradingStatistics.totalReturn >= 0 ? 'profit' : 'loss'">
            {{ virtualTradingStatistics.totalReturn >= 0 ? '+' : '' }}{{ virtualTradingStatistics.totalReturn }}%
          </div>
        </div>
      </el-col>
      
      <el-col :span="8">
        <div class="stat-card">
          <div class="stat-title">夏普比率</div>
          <div class="stat-number" :class="virtualTradingStatistics.sharpeRatio > 1 ? 'profit' : virtualTradingStatistics.sharpeRatio > 0 ? 'neutral' : 'loss'">
            {{ virtualTradingStatistics.sharpeRatio }}
          </div>
          <div class="stat-detail">
            风险调整后收益
          </div>
        </div>
      </el-col>
      
      <el-col :span="8">
        <div class="stat-card">
          <div class="stat-title">交易天数</div>
          <div class="stat-number">{{ virtualTradingStatistics.tradingDays }}</div>
          <div class="stat-detail">
            策略: {{ 
              backtestSettings.strategyType === 'ma_cross' ? 'MA交叉' :
              backtestSettings.strategyType === 'rsi' ? 'RSI策略' :
              backtestSettings.strategyType === 'bollinger' ? '布林带' : 
              backtestSettings.strategyType === 'ml_strategy1' ? 'AI智能策略1' : '自定义'
            }}
          </div>
        </div>
      </el-col>
    </el-row>
  </el-card>
</template>

<script>
import { DataAnalysis } from '@element-plus/icons-vue'

export default {
  name: 'TradingStatistics',
  components: {
    DataAnalysis
  },
  props: {
    isVirtualTrading: {
      type: Boolean,
      required: true
    },
    virtualTradingResults: {
      type: Object,
      required: true
    },
    virtualTradingStatistics: {
      type: Object,
      required: true
    },
    backtestSettings: {
      type: Object,
      required: true
    }
  }
}
</script>

<style scoped>
.stat-card {
  background: #ffffff;
  border-radius: 8px;
  padding: 16px;
  text-align: center;
  border: 1px solid #e2e8f0;
  transition: all 0.3s ease;
  height: 100%;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.stat-title {
  font-size: 12px;
  color: #64748b;
  margin-bottom: 8px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-number {
  font-size: 18px;
  font-weight: bold;
  color: #1e293b;
  margin-bottom: 4px;
  line-height: 1.2;
}

.stat-detail {
  font-size: 11px;
  color: #94a3b8;
  line-height: 1.3;
}

.stat-number.profit {
  color: #14b143;
}

.stat-number.loss {
  color: #ef232a;
}

.stat-number.neutral {
  color: #f59e0b;
}
</style>